<?php
namespace app\home\controller;
use think\Controller;
use think\View;
use think\Db;
use think\Url;
use think\Request;
use app\admin\models\Goods;
use app\admin\models\Cart;
class Checkout extends Controller
{
    public function checkout()
    {	$goods_id=input('param.goods_id');
    	if($goods_id){
    		$god=Goods::get($goods_id)->toArray();
    		//print_r($god);
    		$data=[
    		'user_id'=>1,
    		'goods_id'=>$god['goods_id'],
    		'goods_sn'=>$god['goods_sn'],
    		'goods_name'=>$god['goods_name'],
    		'goods_price'=>$god['price'],    		
    		'dateline'=>time()
    		];
    		$cart=new Cart;
    		$ct=$cart->insert($data);
    		if($ct){
				$this->success('添加购物车成功',url('home/checkout/checkout'));
			}else{
				$this->error('添加购物车失败',url('home/product/product'));
			}


    	}

    	$cat=Cart::all(['user_id'=>1])->toArray();
    	//print_r($cat);
    	$this->assign('cat',$cat);

	 return $this->fetch('checkout');
	
	}
	
	
}
?>